home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11487 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  45 lines

  1. Newsgroups: comp.lang.c++
  2. Path: uu4news.netcom.com!amc-gw!curtis
  3. From: curtis@amc.com (Curtis Green)
  4. Subject: Re: Memory Leak?
  5. Message-ID: <1996Mar14.165853.5180@amc.com>
  6. Organization: Applied Microsystems Corporation
  7. X-Newsreader: TIN [version 1.1 PL6]
  8. References: <4i2tr9$q6k@newsgate.dircon.co.uk>
  9. Date: Thu, 14 Mar 1996 16:58:53 GMT
  10.  
  11. Chris Pyman (topher@dircon.co.uk) wrote:
  12. : Hi all
  13. : Does anybody know whether the following would lead to a memory leak?
  14. : (Assume this is a Win32 Console App written with Visual C++ v2.0)
  15. : main(int argc, char* argv[]) {
  16. :     CString s1("31-12-99");
  17. :     CString s2;
  18. :     s2 = s1.Mid(0,2) + s1.Mid(3,2) + s1.Mid(6,2);
  19. :     cout << s2;
  20. :     return 0;
  21. : }
  22.  
  23. make sure that CString impelments a copy constructor, overloaded assignment
  24. operator (=), and proper destuctor.  Make sure to read up on those in
  25. your book and you should be able to mimimize the problem.  Food for thought:
  26. Look into useing the strstream class (derived from iostream).  It allows
  27. you to tie a buffer to a stream and manipulate the buffer with all of the
  28. iostream functionality.  I have not needed a string class since I cracked
  29. that nut.
  30.  
  31. --
  32. Be seeing you...
  33.  
  34. Curtis Green    |    Software Engineer
  35. curtis@amc.com    |    Applied Microsystems Embedded Systems
  36.                 |    http://www.amc.com
  37. My opinions are |
  38. expressly mine  |    This year Khan escapes Earth on the Botany Bay.
  39. on my own.      |    (Cliff Clavin, 1996)
  40.